package com.fling.abcde.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.lib.utils.XLog;
import com.fling.abcde.wxapi.utils.WxApiUtils;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	public static WxPayListener mWxPayListener;

	public interface WxPayListener {

		void onPaySuccess();

		void onPayCanceled();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		// mWxApi = WXAPIFactory.createWXAPI(this, Config.WX_APP_ID);
		// mWxApi.handleIntent(getIntent(), this);
		XLog.i("lll");
		if (WxApiUtils.sWxApi != null) {
			WxApiUtils.sWxApi.handleIntent(getIntent(), this);
		}
	}

	@Override
	protected void onNewIntent(Intent intent) {

		super.onNewIntent(intent);
		setIntent(intent);
		if (WxApiUtils.sWxApi != null) {
			WxApiUtils.sWxApi.handleIntent(getIntent(), this);
		}
	}

	@Override
	public void onReq(BaseReq req) {

	}

	@Override
	public void onResp(BaseResp baseResp) {

		switch (baseResp.getType()) {
		// 支付回调
		case ConstantsAPI.COMMAND_PAY_BY_WX:
			// PayResp payResp = (PayResp) baseResp;
			switch (baseResp.errCode) {
			case BaseResp.ErrCode.ERR_OK:
				if (mWxPayListener != null) {
					mWxPayListener.onPaySuccess();
				}
				break;
			default:
				if (mWxPayListener != null) {
					mWxPayListener.onPayCanceled();
				}
			}
			break;
		}
		finish();
	}
}